package com.yugao.fintech.antelope.mps.controller;

import com.yugao.fintech.antelope.base.model.constants.ValidationCons;
import com.yugao.fintech.antelope.mps.model.rqrs.field.MsgFieldResp;
import com.yugao.fintech.antelope.mps.model.rqrs.field.MsgFieldSaveReq;
import com.yugao.fintech.antelope.mps.service.MsgFieldService;
import com.yugao.fintech.antelope.base.ram.ActionType;
import com.yugao.fintech.antelope.base.ram.RamResource;
import com.yugao.fintech.framework.core.response.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/msgField")
@Api(tags = "消息字段")
public class MsgFieldController {
    @Autowired
    private MsgFieldService msgFieldService;

    @ApiOperation(value = "查询消息字段")
    @GetMapping("/listMsgField")
    @RamResource(action = "msg:msgField:query", name = "查询消息字段", type = ActionType.READ)
    public Resp<List<MsgFieldResp>> listMsgField(@NotNull(message = ValidationCons.NOT_EMPTY) @RequestParam("taskId") Long taskId) {
        return Resp.ok(msgFieldService.listMsgField(taskId));
    }

    @ApiOperation(value = "保存消息字段")
    @PostMapping("/batchSaveMsgField/{taskId}")
    @RamResource(action = "msg:msgField:save", name = "保存消息字段", type = ActionType.WRITE)
    public Resp<?> saveMsgField(@NotNull(message = ValidationCons.NOT_EMPTY) @PathVariable("taskId") Long taskId,
                                @Validated @RequestBody List<MsgFieldSaveReq> reqList) {
        return Resp.ok(msgFieldService.batchSaveMsgField(taskId, reqList));
    }
}
